/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.bean.Tax;
import com.openbravo.bean.TaxCategory;
import com.openbravo.bean.TaxCustCategory;
import com.openbravo.data.model.Field;

/**
 *
 * @author Administrator
 */
public class TaxDAO extends ModifiedLogDAO<Tax>{

    public TaxDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                "TAXES",
                new Field[]{
                          new Field("ID",Datas.STRING,Formats.STRING),
                          new Field("NAME",Datas.STRING,Formats.STRING),
                          new Field("CATEGORY",Datas.STRING,Formats.STRING,TaxCategory.class),//AppLocal.getIntString("label.taxcategory")),
                          new Field("CUSTCATEGORY",Datas.STRING,Formats.STRING,TaxCustCategory.class),// AppLocal.getIntString("label.custtaxcategory")),
                          new Field("PARENTID",Datas.STRING,Formats.STRING,Tax.class),// AppLocal.getIntString("label.taxparent")),
                          new Field("RATE",Datas.DOUBLE,Formats.PERCENT),
                          new Field("RATECASCADE",Datas.BOOLEAN,Formats.BOOLEAN),
                          new Field("RATEORDER",Datas.INT,Formats.INT),
                          new Field("LASTMODIFIED",Datas.TIMESTAMP, Formats.TIMESTAMP)
                },
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, Tax obj) throws BasicException {
         dp.setString(1,obj.getId());
         dp.setString(2,obj.getName());
         dp.setString(3,obj.getTaxCategoryID());
         dp.setString(4,obj.getTaxCustCategoryID());
         dp.setString(5,obj.getParentID());
         dp.setDouble(6, obj.getRate());
         dp.setBoolean(7,obj.isCascade());
         dp.setInt(8,obj.getOrder());
         dp.setTimestamp(9, obj.getLastModified());
    }

    public Tax readValues(DataRead dr,Tax obj) throws BasicException {
        if(obj==null)
        	obj=new Tax();
    	obj.setID(dr.getString(1));
        obj.setName(dr.getString(2));
        obj.setTaxCategoryID(dr.getString(3));
        obj.setTaxCustCategoryID(dr.getString(4));
        obj.setParentID(dr.getString(5));
        obj.setRate(dr.getDouble(6));
        obj.setCascade(dr.getBoolean(7));
        obj.setOrder(dr.getInt(8));   
        obj.setLastModified(dr.getTimestamp(9));
        return obj;
    }

    @Override
    public Class getSuportClass() {
        return Tax.class;
    }
}
